POV-Ray : Newsgroups : povray.general : Help Trace (easy) : Re: Help Trace (easy) Server Time
3 Aug 2024 12:20:06 EDT (-0400)
  Re: Help Trace (easy)  
From: Tom Melly
Date: 17 Feb 2004 08:03:16
Message: <40321114$1@news.povray.org>
"Jettero Heller" <pov### [at] voltar-confedorg> wrote in message
news:slr### [at] corkyvoltar-confedorg...

> I just re-read the trace section and didn't really even turn up a
> hint as to how to call/use the macro.

Really? (6.1.4.5)

Here's an example that returns the Max and Min values for Z for a sphere
centered at 0 when traced from a negative z direction
(as you would expect, the max value is a little less than 0, since the trace
cannot hit the other side of the sphere where z would be a positive value).

#declare Thing = sphere{0,1} //an object to perform the trace on
#declare MyX = -10; // start x position for trace
#declare MinZ = 100;    // a silly value
#declare MaxZ = -100; // another silly value
#declare StepX = 0.001; // how much to increase the x position by on each trace
#declare Towards = <0,0,1>; // direction to trace towards
#declare MyNormal = <0,0,0>; // a vector to hold the returned normal
#while(MyX < 10) // a while loop
  #declare From = <MyX, 0, -10>; // set the initial vector for the trace
  #declare MyTrace = trace(Thing, From, Towards, MyNormal); // do the trace
  #if(vlength(MyNormal)!=0)  // check that the normal isn't <0,0,0> (which would
mean that we missed the object)
    #debug concat("Z=", str(MyTrace.z, 0,5), "\n") //output the current z value
    #if(MyTrace.z < MinZ) #declare MinZ = MyTrace.z; #end // record a new min if
appropriate
    #if(MyTrace.z > MaxZ) #declare MaxZ = MyTrace.z; #end // recored a new max
if appropriate
  #end
  #declare MyX = MyX+StepX; // increment the x-trace position for the next pass
#end

#debug concat("Min Z = ", str(MinZ, 0, 5), "\n") // output the min value for z
that was found
#debug concat("Max Z = ", str(MaxZ, 0, 5), "\n") // output the max value for z
that was found


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.